<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>map方法的应用</title>
    
</head>
<body>
    <script type="text/javascript">
        var oldArray = [
            {
                name: '张三',
                age: 27
            },
            {
                name: '李四',
                age: 30
            },
            {
                name: '王五',
                age: 43
            }
        ];
        // var newNames = [];
        // var newAges = [];
        // console.log(oldArray);
        // for(var i=0;i<oldArray.length;i++){
        //     var myName = oldArray[i].name;
        //     var myAge = oldArray[i].age;

        //     newNames.push(myName);
        //     newAges.push(myAge);
        // }
        // console.log('newNames:' + newNames);
        // console.log('newAges:' + newAges);

        var newNames = oldArray.map(function(item,index){
            return item.name;
        });
        var newAges = oldArray.map(function(item,index){
            return item.age;
        });
        console.log('newNames:' + newNames);
        console.log('newAges:' + newAges);
    </script>
</body>
</html>